﻿/*
	Copyright © Bogdan Kobets 2011
	http://ElasticLogic.com
*/

using System;
using ElasticLogic.TagsMarker.Filter;

namespace ElasticLogic.TagsMarker.Concepts
{

	public abstract class Label : IComparable<Label>, IEquatable<Label>
	{
		public string Caption { get; private set; }

		public bool CaseSensitive { get; private set; }

		public Label(bool caseSensitive)
		{
			this.CaseSensitive = caseSensitive;
		}

		public bool SetCaption(string caption)
		{
			if (string.IsNullOrEmpty(caption))
				return false;

			string temp = caption.Trim();

			if (temp.Length > 0)
			{
				this.Caption = temp;
				return true;
			}
			else
				return false;
		}

		public override string ToString()
		{
			return this.Caption;
		}

		public int CompareTo(Label other)
		{
			return string.Compare(this.Caption, other.Caption, !CaseSensitive);
		}

		public bool Equals(Label other)
		{
			return (this == other ||
				string.Compare(this.Caption, other.Caption, !CaseSensitive) == 0);
		}

		#region Operators overloading

		public static AND operator &(Label left, Label right)
		{
			return new AND(left, right);
		}

		public static OR operator |(Label left, Label right)
		{
			return new OR(left, right);
		}

		public static NOT operator !(Label rule)
		{
			return new NOT(rule);
		}

		#endregion Operators overloading

	}

}
